package com.realbrand.net.realbrandpay.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.realbrand.net.realbrandpay.R;
import com.realbrand.net.realbrandpay.bean.OrderChildBean;
import com.realbrand.net.realbrandpay.zxing.util.L;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Administrator on 2018/5/19.
 */

public class CommdityDeailAdapter extends BaseAdapter {
    private Context mContext;
    private List<OrderChildBean> list;
    private LayoutInflater inflater;

    public CommdityDeailAdapter(Context mContext, List<OrderChildBean> list) {
        this.mContext = mContext;
        this.list = list;
        inflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        CommodityDeailViewHolder commodityDeailViewHolder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.orderdeail_lv_item_layout, parent, false);
            commodityDeailViewHolder = new CommodityDeailViewHolder(convertView);
            convertView.setTag(commodityDeailViewHolder);
        } else {
            commodityDeailViewHolder = (CommodityDeailViewHolder) convertView.getTag();
        }
        String[] split = list.get(position).getCommodityLog().split(",");
        Picasso.with(mContext).load(split[0]+split[1]).into(commodityDeailViewHolder.commodityLog);
        commodityDeailViewHolder.commodityName.setText(list.get(position).getCommodityName());
        commodityDeailViewHolder.commodityPrice.setText(list.get(position).getCommodityPrice());
        commodityDeailViewHolder.commoditySum.setText("x"+list.get(position).getCommoditySum());
        return convertView;
    }

    class CommodityDeailViewHolder {
        private ImageView commodityLog;
        private TextView commodityName;
        private TextView commodityPrice;
        private TextView commoditySum;

        public CommodityDeailViewHolder(View view) {
            commodityName = (TextView) view.findViewById(R.id.orderDetail_lv_item_tv_commodityName);
            commodityLog = (ImageView) view.findViewById(R.id.orderDetail_lv_item_iv_commodity);
            commodityPrice = (TextView) view.findViewById(R.id.orderDetail_lv_item_tv_money);
            commoditySum = (TextView) view.findViewById(R.id.orderDetail_lv_item_tv_sum);
        }
    }
}
